// error.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"
#include "error.h"

#pragma data_seg(".shared")
const char* glErrorMsg = NULL;
#pragma data_seg() 
#pragma comment(linker,"/SECTION:.shared,RWS") 


ERROR_API const char* JTVGetErrorMsg(int nErrorCode)
{
    switch (nErrorCode)
    {
    case FILE_NOT_FOUND:
        return "Cannot find image file.";
    case MODEL_NOT_FOUND:
        return "Cannot find model file.";
    case IMAGE_LOAD_ERROR:
        return "Error Loading Image.";
    case IMAGE_SIZE_ERROR:
        return "Image size error.";
    default:
        return "no detail message";
    }
}

ERROR_API const char* JTVGetLastErrorMsg()
{
    return glErrorMsg ? glErrorMsg : "no detail message";
}

ERROR_API void JTVSetLastErrorMsg(const char* msg)
{
    if (glErrorMsg)
    {
        delete[] glErrorMsg;
        glErrorMsg = NULL;
    }

    if (!msg)
    {
        return;
    }

    char* err = new char[strlen(msg)+1];
    strcpy(err, msg);
    glErrorMsg = err;
}

